package com.kmvc.message.tools;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

public class WebService {
	private static String HTURL = "http://222.221.20.141:8099/WebServiceTest.asmx";
	private static String SOAP_ACTION_Message = "http://tempuri.org/DataSms";
	//private static String SOAP_ACTION_Message = "http://tempuri.org/DataSmsORA";
	private static String SOAP_ACTION_RefshMessage = "http://tempuri.org/RefshDataSms";
	//private static String SOAP_ACTION_RefshMessage = "http://tempuri.org/DataSmsORARefsh";
	private static String SOAP_ACTION_Yanzheng = "http://tempuri.org/GetYanZhen";
	//private static String SOAP_ACTION_Yanzheng = "http://tempuri.org/GetYanZhenORA";
	private static String SOAP_ACTION_Savepwd = "http://tempuri.org/Savepwd";
	//private static String SOAP_ACTION_Savepwd = "http://tempuri.org/SavepwdORA";
	private static String SOAP_ACTION_CheckBind = "http://tempuri.org/CheckBind";
	//private static String SOAP_ACTION_CheckBind = "http://tempuri.org/CheckBindORA";
    private static String SOAP_ACTION_AddBind = "http://tempuri.org/AddBind";
	//private static String SOAP_ACTION_AddBind = "http://tempuri.org/AddBindORA";
	private static String SOAP_ACTION_CheckPhoneKey = "http://tempuri.org/CheckPhoneKey";
	//private static String SOAP_ACTION_CheckPhoneKey = "http://tempuri.org/CheckPhoneKeyORA";	
	private static String SOAP_ACTION_ExceptionAdd="http://tempuri.org/ExceptionAdd";
	private static String SOAP_ACTION_Fankui="http://tempuri.org/FankuiAdd";
	
	private static String SOAP_ACTION_getAreaSetting="http://tempuri.org/getAreaSetting";
	private static String SOAP_ACTION_getImgTable="http://tempuri.org/getImgTable";
	private static String SOAP_ACTION_GetNewYanzhengCode="http://tempuri.org/getImgTable";
	
	public static String Fankui(String mesString,String Lianxi){
		String ResponseString = null;
		SoapObject rpc = new SoapObject("http://tempuri.org/", "FankuiAdd");
		rpc.addPropertyIfValue("fankui", mesString);
		rpc.addPropertyIfValue("lianxi", Lianxi);
		 
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER12);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(HTURL);
		ht.debug = true;
		try {ht.call(SOAP_ACTION_Fankui, envelope);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
		try {Object detail = envelope.getResponse();
			ResponseString = detail.toString();
		} catch (Exception e) {
			e.printStackTrace();}
		return ResponseString;}
	
	public static String ExceptionAdd(String ex,String OS,String Moldel)
	{
		String ResponseString = null;
		SoapObject rpc = new SoapObject("http://tempuri.org/", "ExceptionAdd");
		rpc.addPropertyIfValue("ex", ex);
		rpc.addPropertyIfValue("os", OS);
		rpc.addPropertyIfValue("model", Moldel);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER12);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(HTURL);
		ht.debug = true;
		try {
			ht.call(SOAP_ACTION_ExceptionAdd, envelope);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
		try {
			Object detail = envelope.getResponse();
			ResponseString = detail.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseString;
	}
	
	/***
	 * 检查绑定
	 * 
	 * @param imsi
	 * @param molno
	 * @return
	 */
	public static String CheckBind(String imsi, String molno) {
		String ResponseString = null;
		SoapObject rpc = new SoapObject("http://tempuri.org/", "CheckBind");
		//SoapObject rpc = new SoapObject("http://tempuri.org/", "CheckBindORA");
		
		rpc.addPropertyIfValue("imsi", imsi);
		rpc.addPropertyIfValue("molno", molno);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER12);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(HTURL);
		ht.debug = true;
		try {
			ht.call(SOAP_ACTION_CheckBind, envelope);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
		try {
			Object detail = envelope.getResponse();
			ResponseString = detail.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseString;

	}

	/**
	 * 增加绑定
	 * 
	 * @param phonenumber
	 * @param imsi
	 * @param molno
	 * @return
	 */
	public static String AddBind(String phonenumber, String imsi, String molno) {

		String ResponseString = null;
		SoapObject rpc = new SoapObject("http://tempuri.org/", "AddBind");
		rpc.addPropertyIfValue("PhoneNumber", phonenumber);
		rpc.addPropertyIfValue("imsi", imsi);
		rpc.addPropertyIfValue("molno", molno);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER12);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(HTURL);
		ht.debug = true;
		try {
			ht.call(SOAP_ACTION_AddBind, envelope);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
		try {
			Object detail = envelope.getResponse();
			ResponseString = detail.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseString;

	}

	/**
	 * 刷新信息
	 * 
	 * @param IMSI
	 * @param MolNo
	 * @param todaymessage
	 * @return
	 */

	public static String RefshCDMA(String IMSI, String MolNo, int todaymessage) {
		String ResponseString = null;
		SoapObject rpc = new SoapObject("http://tempuri.org/", "RefshDataSms");
		rpc.addPropertyIfValue("imsi", IMSI);
		rpc.addPropertyIfValue("molno", MolNo);
		rpc.addPropertyIfValue("messagecount", todaymessage);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER12);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(HTURL);
		ht.debug = true;
		try {
			ht.call(SOAP_ACTION_RefshMessage, envelope);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
	
		try {
			Object detail = envelope.getResponse();
			 ResponseString = detail.toString();
			//sBuilder.append(detail.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseString;
	}

	/**
	 * 获取信息
	 * 
	 * @param IMSI
	 * @param MolNo
	 * @return
	 */
	public static String CDMA(String IMSI, String MolNo) {
		String ResponseString = null;
		SoapObject rpc = new SoapObject("http://tempuri.org/", "DataSms");
		rpc.addPropertyIfValue("imsi", IMSI);
		rpc.addPropertyIfValue("molno", MolNo);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER12);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(HTURL);
		ht.debug = true;
		try {
			ht.call(SOAP_ACTION_Message, envelope);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
		try {
			Object detail = envelope.getResponse();
			ResponseString = detail.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseString;
	}

	/**
	 * 生成验证
	 * 
	 * @param phonenumber
	 * @param imsi
	 * @param molno
	 * @return
	 */
	public static String GetYanZhen(String phonenumber, String imsi,
			String molno) {
		String ResponseString = null;
		SoapObject rpc = new SoapObject("http://tempuri.org/", "GetYanZhen");
		rpc.addPropertyIfValue("phone", phonenumber);
		rpc.addPropertyIfValue("imsi", imsi);
		rpc.addPropertyIfValue("molno", molno);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER12);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(HTURL);
		ht.debug = true;
		try {
			ht.call(SOAP_ACTION_Yanzheng, envelope);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
		try {
			Object detail = envelope.getResponse();
			ResponseString = detail.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseString;
	}

	/**
	 * 保存密码
	 * 
	 * @param IMSI
	 * @param pwd
	 * @return
	 */
	public static String Savepwd(String IMSI, String pwd) {
		String ResponseString = null;
		SoapObject rpc = new SoapObject("http://tempuri.org/", "Savepwd");
		rpc.addPropertyIfValue("imsi", IMSI);
		rpc.addPropertyIfValue("pwd", pwd);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER12);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(HTURL);
		ht.debug = true;
		try {
			ht.call(SOAP_ACTION_Savepwd, envelope);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
		try {
			Object detail = envelope.getResponse();
			ResponseString = detail.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseString;
	}

	/**
	 * 检查手机号码和验证码对应关系
	 * 
	 * @param phonenumber
	 * @param yankey
	 * @return
	 */
	public static String CheckPhoneAndKey(String phonenumber, String yankey) {
		String ResponseString = null;
		SoapObject rpc = new SoapObject("http://tempuri.org/", "CheckPhoneKey");
		rpc.addPropertyIfValue("phonenumber", phonenumber);
		rpc.addPropertyIfValue("yankey", yankey);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER12);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(HTURL);
		ht.debug = true;
		try {
			ht.call(SOAP_ACTION_CheckPhoneKey, envelope);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
		try {
			Object detail = envelope.getResponse();
			ResponseString = detail.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseString;
	}
	
	
	public static String getAreaSetting(String LastDate)
	{
		String ResponseString = null;
		SoapObject rpc = new SoapObject("http://tempuri.org/", "getAreaSetting");
		rpc.addPropertyIfValue("LastDate", LastDate);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER12);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(HTURL);
		ht.debug = true;
		try {
			ht.call(SOAP_ACTION_getAreaSetting, envelope);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
	
		try {
			Object detail = envelope.getResponse();
			 ResponseString = detail.toString();
			//sBuilder.append(detail.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseString;
	}
	
	public static String getImgTable(String LastDate)
	{
		String ResponseString = null;
		SoapObject rpc = new SoapObject("http://tempuri.org/", "getImgTable");
		rpc.addPropertyIfValue("Lastdate", LastDate);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER12);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(HTURL);
		ht.debug = true;
		try {
			ht.call(SOAP_ACTION_getImgTable, envelope);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
	
		try {
			Object detail = envelope.getResponse();
			 ResponseString = detail.toString();
			//sBuilder.append(detail.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseString;
	}
	
	
	public static String GetNewYanzhengCode(String phoneNum,String imsi,String molno)
	{
		String ResponseString = null;
		SoapObject rpc = new SoapObject("http://tempuri.org/", "GetNewYanzhengCode");
		rpc.addPropertyIfValue("phoneNum", phoneNum);
		rpc.addPropertyIfValue("imsi", imsi);
		rpc.addPropertyIfValue("molno", molno);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER12);
		envelope.bodyOut = rpc;
		envelope.dotNet = true;
		envelope.setOutputSoapObject(rpc);
		HttpTransportSE ht = new HttpTransportSE(HTURL);
		ht.debug = true;
		try {
			ht.call(SOAP_ACTION_GetNewYanzhengCode, envelope);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}
	
		try {
			Object detail = envelope.getResponse();
			 ResponseString = detail.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ResponseString;
	}
	
	
	
	
}
